/*******************************************************************************
 * Copyright (c) 2012 AwOiSoAk.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     $AwOiSoAk - initial API and implementation
 ******************************************************************************/
package com.awoisoak.dundeeguide;


import com.madsa.AugmentedCompass.*;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class Restaurant extends Activity implements OnClickListener{
	String coordinate = null;
	String place = null;
	String website = null;
	int explanation = 0;
	int iconPlace = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.restaurant);
		
		TextView tvRestaurant= (TextView)findViewById(R.id.tvRestaurant);
		TextView tvExplanation= (TextView)findViewById(R.id.tvExplanation);
		ImageView ic_place= (ImageView)findViewById(R.id.ic_place);
		
		ImageButton iBtMap = (ImageButton)findViewById(R.id.iBtMap);
		ImageButton iBtCompass = (ImageButton)findViewById(R.id.iBtCompass);
		ImageButton iBtBrowser = (ImageButton)findViewById(R.id.iBtBrowser);

		
		iBtMap.setOnClickListener(this);
		iBtCompass.setOnClickListener(this);
		iBtBrowser.setOnClickListener(this);

		
		
		Bundle extras = getIntent().getExtras();
		//try{
			if (extras!= null){ 
				
				coordinate = extras.getString("tag_coordinate");
				place = extras.getString("tag_place");
				explanation = extras.getInt("tag_explanation");
				iconPlace = extras.getInt("tag_icon");
				website = extras.getString("tag_website");

				tvRestaurant.setText(place);
				tvExplanation.setText(explanation);
				ic_place.setImageResource(iconPlace);
				
				//int LUGAR = Integer.parseInt(tagLugar);
				//tvAtracction.setText(LUGAR);
			}

		}

	@Override
	public void onClick(View v) {
		Intent i;
		//We apply a filter to the button when it's pressed
		((ImageView) v).setColorFilter(0xFF0000FF, PorterDuff.Mode.MULTIPLY);
		
		int BUTTON = v.getId();
		
		switch (BUTTON){
			case R.id.iBtMap: 
				i = new Intent (Restaurant.this,Map.class);
				i.putExtra("tag_coordinate", coordinate);
				i.putExtra("tag_place",place);
				startActivity(i);
				break;
				
			case R.id.iBtCompass:
				i = new Intent (Restaurant.this,BrujulaAumentada.class);
				i.putExtra("destineDescription", "    "+place);
				i.putExtra("destineLocation", coordinate);
				i.putExtra("imageName","ar_destino");
				startActivity(i);
				break;		
			case R.id.iBtBrowser:
				
				Uri uri =Uri.parse(website);
				i = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(i);
				
				break;		
		}
	}
	@Override
	protected void onResume() {
		
		//We clear the filters applied on the buttons (if they were set)
		ImageButton iBtBrowser = (ImageButton)findViewById(R.id.iBtBrowser);
		ImageButton iBtMap = (ImageButton)findViewById(R.id.iBtMap);
		ImageButton iBtCompass = (ImageButton)findViewById(R.id.iBtCompass);

		((ImageView) iBtBrowser).clearColorFilter();
		((ImageView) iBtMap).clearColorFilter();
		((ImageView) iBtCompass).clearColorFilter();
		super.onStart();
	}
	
	
	
	
	
}
